// pages/transMy/transMy.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    shenfen: "",
    baseImgPath: app.globalData.baseImgPath,
    userInfo: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    wx.getStorage({
      key: 'sessionId',
      success: function (res) {
        that.setData({
          sessionId: res.data, //登陆页面取回来的sessionId
        });
        wx.request({
          url: app.globalData.urlPath + 'ManagerMent/userInfo',
          data: {
            sessionid: that.data.sessionId,
          },
          method: "POST",
          success: function (res) {
            console.log(res)
            if (res.data.code == 200) {
              that.setData({
                userInfo: res.data.data
              })
            } else {
              wx.showToast({
                title: res.data.error,
                icon: 'none',
                duration: 2000
              })
              if (res.data.code == 5000) {
                wx,
                  wx.redirectTo({
                    url: '/pages/login/login',
                  })
              }
            }
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  //底部导航切换
  handleChangeTab({ detail }) {
    console.log(detail.key)
    if (detail.key == 'order') {
      wx.redirectTo({
        url: '/pages/masterOrderList/masterOrderList',
      })
    } else if (detail.key == 'code') {
      // 只允许从相机扫码
      wx.scanCode({
        onlyFromCamera: true,
        success(res) {
          if (res.result == '') {
            wx.redirectTo({
              url: '../masterOrderList/masterOrderList'
            })
          } else {
            //  wx.redirectTo({
            //    url: '../masterOrderList/masterOrderList?qrcode=' + that.data.qrcode,
            //  })
            wx.navigateTo({
              url: '../masterSubOrder/masterSubOrder?qrcode=' + res.result,
            })
          }
        }
      })


    } else if (detail.key == 'my') {
      wx.redirectTo({
        url: '/pages/masterMy/masterMy',
      })
    }
    this.setData({
      currentTab: detail.key
    });
  },
  //退出登陆
  logout: function () {
    wx.showModal({
      title: '提示',
      content: '确定退出登陆吗?',
      confirmColor: '#ff9734',
      success(res) {
        if (res.confirm) {
          app.globalData.sessionid = ''
          wx.removeStorage({
            key: 'sessionId',
            success: function(res) {},
          })
          wx.redirectTo({
            url: '/pages/login/login',
          })
        } else if (res.cancel) {
          return;
        }
      }
    })
  }
})